<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/9/15 13:36
 * Desc: 会员地址请求验证
 */
class Request_Api_V2_Member_Address extends Request_Api_V2_Base
{
    public function __construct($request_param)
    {
        parent::__construct($request_param);

        //自定义规则
        $this->validation->rule('mid',array('Rule_Member','need_member'));
    }

    public function list()
    {
        $this->rules = [
            ['mid', ['not_empty', 'digit', $this->rule_min(1)]],
            ['pagesize', ['digit', $this->rule_min(1)]],
            ['page', ['digit', $this->rule_min(0)]],
        ];

        return $this;
    }

    public function show_info()
    {
        $this->rules = [
            ['mid', ['not_empty', 'digit', $this->rule_min(1)]],
            ['id', ['not_empty', 'digit', $this->rule_min(1)]],
        ];

        return $this;
    }

    public function delete()
    {
        $this->rules = [
            ['mid', ['not_empty', 'digit', $this->rule_min(1)]],
            ['id', ['not_empty', 'digit', $this->rule_min(1)]],
        ];

        return $this;
    }

    public function insert()
    {
        $this->rules = $this->edit_rule();

        return $this;
    }

    public function update()
    {

        $rules       = $this->edit_rule();
        $rules[]     = ['id', ['not_empty', 'digit', $this->rule_min(1)]];
        $this->rules = $rules;

        return $this;
    }

    /**
     *  添加或者更新的验证条件
     * @return array[]
     */
    public function edit_rule()
    {
        return [
            ['receiver', ['not_empty']],
            ['phone', ['not_empty', 'phone']],
            ['province', ['not_empty']],
            ['city', ['not_empty']],
            ['address', ['not_empty']],
            ['postcode', ['not_empty']],
            ['is_default', ['not_empty', 'digit', $this->rule_in_array(array(0, 1))]],
        ];
    }
}